/*
 * Copyright  bocmbci
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import List from '@ohos.util.List';
import webview from '@ohos.web.webview';
import { CordovaInterface } from './CordovaInterface';
import { PluginEntry } from './PluginEntry';
import { PluginManager } from './PluginManager';
import { PluginResult } from './PluginResult';
import { Context } from '@ohos.abilityAccessCtrl';
import { KeyEvent } from '@ohos.multimodalInput.keyEvent';

export interface CordovaWebViewService{
  // CORDOVA_VERSION: string = "8.1.0";

  // init(cordova: CordovaInterface, pluginEntries: List<PluginEntry>, preferences: CordovaPreferences);
  init(cordova: CordovaInterface, pluginEntries: List<PluginEntry>);

  isInitialized(): boolean;

  getViewController(): webview.WebviewController;

  loadUrlIntoView(url: string, recreatePlugins: boolean): void;

  stopLoading(): void;

  canGoBack(): boolean;

  clearCache(): void;

  clearHistory(): void;

  backHistory(): boolean;

  handlePause(keepRunning: boolean): void;

  // onNewIntent(intent: Intent): void;

  handleResume(keepRunning: boolean): void;

  handleStart(): void;

  handleStop(): void;

  handleDestroy(): void;

  sendJavascript(statememt: string): void;

  showWebPage(url: string, openExternal: boolean, clearHistory: boolean, params: Map<string, any>);

  // isCustomViewShowing(): boolean;
  //
  // hideCustomView(): void;

  setButtonPlumbedToJs(keyCode: number, isOverride: boolean): void;
  isButtonPlumbedToJs(keyCode: number): boolean;

  sendPluginResult(pluginResult: PluginResult, callbackId: string): void;

  getPluginManager(): PluginManager;
  // getEngine(): CordovaWebViewEngine;
  // getCookieManager(): ICordovaCookieManager;

  getUrl(): string;

  // TODO: Work on deleting these by removing refs from plugins.
  getContext(): Context;
  loadUrl(url: string): void;
  postMessage(id: string, data: any): any;

  onDispatchKeyEvent(event: KeyEvent): boolean;
  clearLoadTimeoutTimer(): void;
  onPageStarted(newUrl: string): void;
  onReceivedError(errorCode: number, description: string, failingUrl: string): void;
  onPageFinishedLoading(url: string): void;
  onNavigationAttempt(url: string): boolean;
}
